home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-06-21 | 4.1 KB | 255 lines | [TEXT/CWIE] |
-
- // Maf Vosburgh
-
-
-
- #include <Icons.h>
- #include <QDOffscreen.h>
- #include <ImageCompression.h>
- #include <string.h>
- #include <Palettes.h>
- #include "QDUtils.h"
-
-
-
-
- OSErr PlotSmallIcon(Point p, short iconID)
- {
- Rect r;
-
- SetRect(&r, p.h -8, p.v -8, p.h + 8, p.v + 8);
- return PlotIconID(&r, atNone, ttNone, iconID);
- }
-
-
- OSErr PlotSmallMenuIcon(Point p, short iconID, short transform)
- {
- Rect r;
-
- SetRect(&r, p.h -8, p.v -8, p.h + 8, p.v + 8);
- return PlotIconID(&r, atNone, transform, iconID);
- }
-
-
- void OffsetPt(Point *p, short dh, short dv)
- {
- p->h += dh;
- p->v += dv;
- }
-
-
- short GetGDDepth(GDHandle gd)
- {
- return gd[0]->gdPMap[0]->pixelSize;
- }
-
-
- short GetGDMode(GDHandle gd)
- {
- return gd[0]->gdFlags & 1;
- }
-
- short MaxDepth(GDHandle gd)
- {
- short x;
- for (x = 32 ; x ; x >>=1)
- if (HasDepth(gd, x, 0, 0))
- return x;
-
- return 0;// will never get here
- }
-
-
- void MafInsetRect(Rect *r, short hInset, short vInset)
- {
- r->left += hInset;
- r->right -= hInset;
- r->top += vInset;
- r->bottom -= vInset;
- }
-
- void MafOffsetRect(Rect *r, short hOffset, short vOffset)
- {
- r->left += hOffset;
- r->right += hOffset;
- r->top += vOffset;
- r->bottom += vOffset;
- }
-
- Boolean MafPtInRect(Point p, Rect *r)
- {
- return ((p.h >= r->left) && (p.h <= r->right) && (p.v >= r->top) && (p.v <= r->bottom));
- }
-
- void MafSetRect(Rect *r, short left, short top, short right, short bottom)
- {
- r->top = top;
- r->left = left;
- r->right = right;
- r->bottom = bottom;
-
- }
-
- void ZeroRect(Rect* r)
- {
- MafOffsetRect(r, -r->left, -r->top);
- }
-
- void CentreRect(Rect *subRect, Rect masterRect)
- {
- ZeroRect(subRect);
- MafOffsetRect(subRect, ((masterRect.left + masterRect.right) >>1) - (subRect->right >>1),
- ((masterRect.top + masterRect.bottom) >>1) - (subRect->bottom >>1));
- }
-
-
-
- void HiliteRect(Rect *r)
- {
- // clear high bit of HiliteMode lo mem global
- #ifdef THINK_C
- BitClr ((Ptr)0x938, pHiliteBit); // pHiliteBit = 0, as BitClr goes from high to low
- #else
- LMSetHiliteMode( LMGetHiliteMode() & 0x7F );
- #endif
-
- InvertRect(r); // this InvertRect now hilites, not inverts
- } // HiliteMode is reset automatically
- // by QuickDraw
-
-
-
-
- short RWidth(Rect r)
- {
- return r.right - r.left;
- }
-
- short RHeight(Rect r)
- {
- return r.bottom - r.top;
- }
-
- // little utility proc, like SetRect
- void SetRGBColor(RGBColor *rgb, unsigned short r,unsigned short g,unsigned short b)
- {
- rgb->red = r;
- rgb->green = g;
- rgb->blue = b;
- }
-
-
- void SetRGBBackColor(unsigned short r,unsigned short g,unsigned short b)
- {
- RGBColor rgb;
-
- SetRGBColor(&rgb, r,g,b);
-
- RGBBackColor(&rgb);
- }
-
-
-
- void SetRGBForeColor(unsigned short r,unsigned short g,unsigned short b)
- {
- RGBColor rgb;
-
- SetRGBColor(&rgb, r,g,b);
-
- RGBForeColor(&rgb);
- }
-
- void QDNormal(void)
- {
- ForeColor(blackColor);
- BackColor(whiteColor);
- PenNormal();
- }
-
-
-
- void LocalToGlobalRect(Rect * r)
- {
- LocalToGlobal( (Point*) r);
- LocalToGlobal( (Point*) r + 1);
- }
-
- void GlobalToLocalRect(Rect * r)
- {
- GlobalToLocal( (Point*) r);
- GlobalToLocal( (Point*) r + 1);
- }
-
-
- Point GetWindowLoc(WindowPtr theWindow)
- {
- GrafPtr savePort;
- Point windowLoc = {0,0};
-
- GetPort(&savePort);
- SetPort(theWindow);
- LocalToGlobal(&windowLoc);
- SetPort(savePort);
- return windowLoc;
- }
-
-
- short WindowToDepth(WindowPtr theWindow)
- {
- GrafPtr savePort;
- GDHandle gd;
- Rect windowRect;
-
- GetPort(&savePort);
- SetPort(theWindow);
- windowRect = theWindow->portRect;
- LocalToGlobalRect(&windowRect);
- SetPort(savePort);
- gd = GetMaxDevice(&windowRect);
- if (!gd)
- gd = GetMainDevice();
- return (*(*gd)->gdPMap)->pixelSize;
- }
-
- GDHandle GetCurrentGD(Point loc)
- {
- GDHandle gD = GetDeviceList();
-
- do
- {
- if (PtInRect(loc, &gD[0]->gdRect))
- return gD;
- else
- gD = (GDHandle) gD[0]->gdNextGD;
- }
- while (gD);
-
- return nil;
- }
-
-
-
- // example AlignRect(&movableRect, fixedRect, kAlignTop + kAlignRight);
-
- void AlignRect(Rect *r1, Rect r2, short alignCode)
- {
- short xOffset = 0;
- short yOffset = 0;
-
- if (alignCode & kAlignRectLeft)
- xOffset = r2.left - r1->left;
- else if (alignCode & kAlignRectRight)
- xOffset = r2.right - r1->right;
-
-
- if (alignCode & kAlignRectTop)
- yOffset = r2.top - r1->top;
- else if (alignCode & kAlignRectBottom)
- yOffset = r2.bottom - r1->bottom;
-
- MafOffsetRect(r1, xOffset, yOffset);
- }
-
-
-
-